package com.imooc.common.controller;

import cn.hutool.json.JSONUtil;
import com.imooc.chart.service.UserService;
import com.imooc.common._this.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
public class CommonController {


    @Value("${my.test}")
    private String test;


    @Autowired
    private UserService userService;


    @GetMapping("/helloWord")
    public String helloWord(HttpServletResponse response) {

        return "helloWord";
    }

    @GetMapping("/export")
    public void exportUsersToExcel(HttpServletResponse response) {
        userService.exportUsersToExcel(response);
    }


    @RequestMapping("/run2")
    public Object run2(@RequestBody UserRequest userRequest){
        System.out.println(JSONUtil.toJsonStr(userRequest));

        return JSONUtil.toJsonStr(userRequest);
    }

    @RequestMapping("/run3")
    public Object run3( Role role){
        System.out.println(JSONUtil.toJsonStr(role));

        return JSONUtil.toJsonStr(role);
    }


    @RequestMapping("/run1")
    public Object run1(){

        return test;
    }

}
